<?php

namespace app\api\validate;

use think\Validate;

class UniversalValidate extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'phone' => ['require', 'regex' => '/^((13[0-9])|(17[0-1,6-8])|(15[^4,\\D])|(18[0-9]))\d{8}$/'],
        'code' => ['require'],
        'lat' => 'require',
        'lng' => 'require',
        'head_img' => ['require', 'file', 'fileExt' => ['jpg', 'jpeg', 'gif', 'png']],
        'user_id' => ['require'],
        'user_nickname' => 'require|length:1,10',
        'user_gender' => 'require|in:1,2',
        'user_age' => 'require|between:18,60',
        'open_id' => 'require',
        'photo_id' => 'require',
        'square_title' => 'require|length:5,500',
        'square_country' => 'require',
        'square_province' => 'require',
        'square_city' => 'require',
        'square_district' => 'require',
        'square_id' => 'require',
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [];

    /**
     * 验证场景
     * @var [type]
     */
    protected $scene = [
        'getVerifyCode'  =>  ['phone'], 
        'checkLogin' => ['phone', 'code', 'lat', 'lng'],
        'checkHeadImage' => ['head_img', 'user_id'],
        'checkUserInfo' => ['user_nickname', 'user_gender', 'user_age', 'user_id'],
        'checkWx' => ['open_id', 'lat', 'lng'],
        'bindingWx' => ['open_id', 'phone', 'code', 'lat', 'lng'],
        'checkNickname' => ['user_id', 'user_nickname'],
        'checkAgeOrSignature' => ['user_id'],
        'checkChangePhone' =>['phone', 'code', 'user_id'],
        'checkUploadPhotoWall' => ['user_id'],
        'getPhotoWall' => ['user_id'],
        'delPhotoWall' => ['user_id', 'photo_id'],
        'shareSquare' => ['user_id', 'square_title', 'lat', 'lng', 'square_country', 'square_province', 'square_city', 'square_district'],
        'photoSquare' => ['square_id'],
    ];
}
